package sql.ddl.coluna;

import java.util.ArrayList;

import sql.ddl.TokensSQL;

public class ListaColuna extends ArrayList<Coluna> implements TokensSQL {
	private static final long serialVersionUID = -1933614960144003975L;

	public String codigoSQL() {
		String s = lerRegistro(get(0));
		for (int i = 1; i < size(); i++) {
			s += VIRGUL + SPACE + lerRegistro(get(i));
		}
		return s;
	}

	private String lerRegistro(Coluna coluna) {
		try {
			return coluna.codigoSQL();
		} catch (Exception e) {
			ListaColuna cls = ((ColunaComposta) coluna).getChaves();
			
			String s = lerRegistro(cls.get(0));
			for (int i = 1; i < cls.size(); i++) {
				try {
					s += VIRGUL + SPACE + cls.get(i).codigoSQL();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
			return s;
		}
	}
	public boolean add(Coluna coluna) {
		return contains(coluna) ? false : super.add(coluna);
	}
	

}
